/**
 * Created by Administrator on 2017/9/18.
 */
/**
 * Created by yang on 2016/12/25.
 */
var globelTempId ='';
function m$y(obool, newMaskClassName) {
  this.scroll = function (fn) {
    window.onscroll = function () {
      var wScrollY = window.scrollY; // 当前滚动条位置
      var wInnerH = window.innerHeight; // 设备窗口的高度（不会变）
      var bScrollH = document.body.scrollHeight; // 滚动条总高度
      if (wScrollY + wInnerH >= bScrollH) {
        if (typeof fn === 'function') {
          fn()
        }
      }
    }
  };
  this.template = function (obj) {

    var temp_h = document.documentElement.clientHeight;
    var temp_w = document.documentElement.clientWidth;
    var newNode = document.createElement('div');
    newNode.id = 'templateWarp';
    var thisValue = (obj.val ? obj.val : '<img src="" ' +
      'style="height: 0.5rem; vertical-align: middle;">');
    newNode.innerHTML = "<div style='display: inline-block;  color: white;  padding: 0.2rem 0.14rem; font-size: 0.28rem;text-align: center;" +
      " background:rgba(0,0,0,0.71);  border-radius:0.1rem;max-width:40%;min-width: 1.46rem;" +
      " position: absolute;  left: 50%;  top: 50%; box-sizing: border-box; transform:translate(-50%,-50%);  " +
      "-webkit-transform:translate(-50%,-50%);  -o-transform:translate(-50%,-50%);  -moz-transform:translate(-50%,-50%);  " +
      "-ms-transform:translate(-50%,-50%);'>" +
      thisValue +
      "</div>"
    newNode.style.cssText = "height:" + temp_h + "px;width:" + temp_w + "px;top:0;left:0;position: fixed;z-index:9999999999999;";
    var thisBody = document.body;
    if (!document.getElementById('templateWarp')) {
      thisBody.appendChild(newNode);
    }
    else {
      var ooojj = document.querySelectorAll('#templateWarp>div')[0];
      ooojj.innerHTML = thisValue;
      clearTimeout(globelTempId)
    }

    if (('time' in obj) && (typeof obj.time == 'number')) {

      globelTempId = window.setTimeout(function () {
        var willRemoveNode = document.getElementById('templateWarp');
        thisBody.removeChild(willRemoveNode);
        if (('fn' in obj) && (typeof obj.fn == 'function')) {
          obj.fn()
        }
      }, obj.time)
    }

  };
  this.hiddenScroll = function (oval) {
    window.scrollTo(0, 0)
    var temp_h1 = document.body.clientHeight;
    var temp_h2 = document.documentElement.clientHeight;

    var isXhtml = (temp_h2 <= temp_h1 && temp_h2 != 0) ? true : false;
    var htmlbody = isXhtml ? document.documentElement : document.body;
    if (oval === false) {
      htmlbody.style.overflow = "auto";
    } else if (oval === true) {
      htmlbody.style.overflow = "hidden";
    }
    else if (oval && typeof oval == 'string') {
      this.dom(oval)[0].style.height = document.documentElement.clientHeight + 'px'
    }
    return htmlbody.clientHeight;

  };
  this.resizes = function (fonts, initW, obool) {
    var myIndoc = window.document.documentElement;
    var myIndocWidth = window.document.documentElement.clientWidth;
    var myInft = fonts * myIndocWidth / initW;
    myIndoc.style.fontSize = myInft + 'px';
    this.rem = myInft;
    this.precent = myIndocWidth / initW
  };
  this.dom = function (t) {
    var mynodes = document.querySelectorAll(t);
    if (mynodes && mynodes.length >= 1) {
      mynodes["bind"] = function (obj) {
        mynodes.forEach(function (oitem, oindex) {
          for (var key in obj) {
            oitem.addEventListener(key, obj[key], true);
          }
        })
      };
      mynodes["unbind"] = function (obj) {
        mynodes.forEach(function (oitem, oindex) {
          for (var key in obj) {
            oitem.removeEventListener(key, obj[key], true);
          }
        })
      };
      //   this.getBoundingClientRect();
    }
    return mynodes
  };
  this.documentTitle = function (val) {

    var $iframe = document.createElement('iframe');

    $iframe.src = "./static/1.html?" + (new Date()).getTime();
    $iframe.style = "display:none;";
    document.title = val;
    console.log($iframe)
    m$.dom('body')[0].appendChild($iframe);
    $iframe.onload = function () {
      window.document.title = val;
      setTimeout(function () {
        window.document.title = val;
        $iframe.onload = null;
        m$.dom('body')[0].removeChild($iframe);
      }, 10);
    }
  }
  this.searchParams = function (ostring) {
    if (ostring.split('?').length <= 1) {
      return {}
    }
    ostring = ostring.split('?')[1];
    var ostrArry = ostring.split("&");
    var get_params = {};
    var oflag = 0;
    while (ostrArry.length - oflag) {
      var little_params = ostrArry[oflag].split('=')
      if (little_params.length == 2) {
        get_params[little_params[0]] = little_params[1];
      }
      else {
        get_params[little_params[0]] = '';
      }
      oflag++;
    }
    ;
    return get_params
  }
  this.searchString = function (obj) {
    var ostring = '?'
    for (var okey in obj) {
      ostring += okey + '=' + obj[okey] + '&'
    }
    return ostring.substring(0, ostring.length - 1);
  }
  this.assign = function () {
    var assignObj = {}
    if (arguments.length < 2) {
      throw '参数错误'
      return
    }
    for (var i = 0; i < arguments.length; i++) {
      for (var ot in arguments[i]) {
        assignObj[ot] = arguments[i][ot]
      }
    }
    return assignObj
  }
}

window.m$=new m$y();
window.m$.localStrages =window.m$.sessionStores
function getDeviceType() {
  var browser = {
    versions: (function() {
      var u = navigator.userAgent, app = navigator.appVersion;
      return {
        trident: u.indexOf('Trident') > -1, //IE内核
        presto: u.indexOf('Presto') > -1, //opera内核
        webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
        gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,//火狐内核
        mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
        ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
        android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
        iPhone: u.indexOf('iPhone') > -1 , //是否为iPhone或者QQHD浏览器
        iPad: u.indexOf('iPad') > -1, //是否iPad
        webApp: u.indexOf('Safari') == -1, //是否web应该程序，没有头部与底部
        weixin: u.indexOf('MicroMessenger') > -1, //是否微信 （2015-01-22新增）
        qq: u.match(/\sQQ/i) == " qq" //是否QQ
      };
    })(),

    language: (navigator.browserLanguage || navigator.language).toLowerCase()
  };

  if(browser.versions.ios || browser.versions.iPhone || browser.versions.iPad) {
    return "IOS";
  }else if(browser.versions.android) {
    return "ANDROID";
  }else if(browser.versions.weixin){ //default
    return "WEIXIN";
  }else {
    return "WEB";
  }
}
function JsBridgeService() {

  var service = {
    setupWebViewJavascriptBridge: setupWebViewJavascriptBridge,
    showLog:showLog
  };

  return service;

  function setupWebViewJavascriptBridge(callback) {
    if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
    if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
    window.WVJBCallbacks = [callback];
    var WVJBIframe = document.createElement('iframe');
    WVJBIframe.style.display = 'none';
    WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
    document.documentElement.appendChild(WVJBIframe);
    setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
  }

  function showLog(log) {

    setupWebViewJavascriptBridge(function(bridge) {

      bridge.callHandler('showLog', log, function responseCallback(responseData) {
      });
    });
  }
}
var JsBridgeService2=JsBridgeService();
var thisVersion = getDeviceType();
var willsg = {}
if(thisVersion== 'ANDROID'){
  if(window.android&&window.android.fetchDeviceInfo()){
    var responseData=JSON.parse(window.android.fetchDeviceInfo());

    for(var okey in responseData){
      if(responseData[okey]!==''){
        willsg[okey] = responseData[okey]
      }
    }
    m$.localStrages.set('willsg',willsg)

  }
}
else if(thisVersion== 'IOS'){
  if(JsBridgeService2){
    JsBridgeService2.setupWebViewJavascriptBridge(function (bridge) {
      bridge.callHandler('kJSFetchDeviceInfo', function (responseData) {
        var responseData=JSON.parse(responseData);
        for(var okey in responseData){
          if(responseData[okey]!==''){
            willsg[okey] = responseData[okey]
          }
        }
        m$.localStrages.set('willsg',willsg)
      });
    });
  }
}
else {

}
// window.setTimeout(function () {
//     m$.dom('.start_page')[0].className='start_page';
//     window.setTimeout(function () {
//         m$.dom('.start_page')[0].parentNode.removeChild(m$.dom('.start_page')[0]);
//     },2000)
// },1000)
window.m$.resizes(100,750);
var ttobj =m$.searchParams(window.location.href);

var newGetInfoData ={};
if(m$.localStrages.get('getInfoData')&&typeof m$.localStrages.get('getInfoData') == 'object'){
  newGetInfoData = m$.localStrages.get('getInfoData');
}
m$.localStrages.set('getInfoData',m$.assign(newGetInfoData,ttobj))
var regUrlString  = window.location.protocol+'//'+window.location.hostname+baseUrl;
if(regUrlString!= window.location.href.split('#!')[0]){
  window.location.href =baseUrl+'#!/index'
}
window.chanNo=m$.localStrages.get('getInfoData')&&m$.localStrages.get('getInfoData').chanNo?m$.localStrages.get('getInfoData').chanNo :100;
window.goNextPath=m$.localStrages.get('getInfoData')&&m$.localStrages.get('getInfoData').prodId?m$.localStrages.get('getInfoData').prodId:'';
m$.localStrages.set('chanNo',window.chanNo);
window.okImgDiv='';
